<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" enctype="multipart/form-data" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">编辑商品分类</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">分类名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="category[name]"
                                           value="<?= $model['name'] ?>" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">上级分类 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="category[parent_id]" class="test"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm'}">
                                        <option value="0">顶级分类</option>
                                        <?php if (isset($list)): foreach ($list as $first): ?>
                                            <option value="<?= $first['category_id'] ?>"
                                                <?= $model['parent_id'] == $first['category_id'] ? 'selected' : '' ?>>
                                                <?= $first['name'] ?></option>
                                        <?php endforeach; endif; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">分类图片 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="am-form-file">
                                        <button type="button"
                                                class="upload-file am-btn am-btn-secondary am-radius">
                                            <i class="am-icon-cloud-upload"></i> 选择图片
                                        </button>

                                        <div class="uploader-list am-cf">
                                            <?php foreach ($images as  $item): ?>
                                                <div class="file-item">
                                                    <a href="<?= $item['file_url'].'/'.$item['file_name'] ?>" title="点击查看大图" target="_blank">
                                                        <img src="<?= $item['file_url'].'/'.$item['file_name'] ?>">
                                                    </a>
                                                    <input type="hidden" name="category[image_id][]"
                                                           value="<?= $item['image_id'] ?>">
                                                    <i class="iconfont icon-shanchu file-item-delete"></i>
                                                </div>
                                            <?php endforeach; ?>
                                        </div>

                                    </div>
                                </div>
                            </div>

                            <div class="am-form-group otherAnswer1">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 所属板块 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <?php foreach ($bakuaiData as $item): ?>
                                        <label class="am-radio-inline">
                                            <input type="radio" name="category[bankuai_id]"
                                                   value="<?= $item['id'] ?>" data-am-ucheck
                                                <?= $model['bankuai_id'] == $item['id'] ? 'checked' : '' ?> >
                                            <?= $item['name'] ?>
                                        </label>
                                    <?php endforeach; ?>
                                </div>
                            </div>


                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">分类排序 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" name="category[sort]"
                                           value="<?= $model['sort'] ?>" required>
                                    <small>数字越小越靠前</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 图片文件列表模板 -->
{{include file="layouts/_template/tpl_file_item" /}}

<!-- 文件库弹窗 -->
{{include file="layouts/_template/file_library" /}}

<script>
    $(function () {

        // 选择图片
        // 选择图片
        $('.upload-file').selectImages({
            name: 'category[image_id][]'
            , multiple: true
        });
//顶级分类不能选择板块
        var sel=$('.test').val();
        if(sel!=="0"){
            $(".otherAnswer1").show();
        }else{
            $(".otherAnswer1").hide();
        }
        $(".test").change(function(){
            if($(this).val()!=="0"){
                $(".otherAnswer1").show();
            }
            else{
                $(".otherAnswer1").hide();
            }

        });
        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

    });
</script>
